//
//  Common.h
//  CloudWalletApp
//
//  Created by 董雷 on 2020/8/7.
//  Copyright © 2020 董雷. All rights reserved.
//

#ifndef Common_h
#define Common_h

// 图片
#define ImageNamed(_pointer) [UIImage imageNamed:(_pointer)]
// 代码块回调
#define BLOCK_EXEC(block,...) !block ?: block(__VA_ARGS__);
// 非空判断
#define NoObject(object,place) object.length>0?object:place
// 屏幕高宽
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
// 状态栏高度
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
// 导航栏高度
#define kNaviHeight 44
// 手机导航栏+状态栏 高度
#define kTopHeight (kStatusBarHeight + kNaviHeight)
// TabBar高度
#define kTabBarHeight self.tabBarController.tabBar.frame.size.height

// 系统版本
#define kIOSVer [[[UIDevice currentDevice] systemVersion]floatValue]
// app的版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
// app build版本号
#define kAppBuildVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 弱指针
#define WeakSelf(type) __weak typeof(type) weak##type = type
//颜色
// UIColor 十六进制RGB_0x
#define UIColorFromRGB_0x(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
// 十六进制 alpha
#define UIColorFromAlphaRGB_0x(rgbValue,A) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:A]
// UIColor 十进制RGB_A
#define UIColorFromRGBA_D(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]
// 默认设置的颜色值
#define BlackColor UIColorFromRGBA_D(0,0,0,1.0)
#define WhiteColor UIColorFromRGBA_D(255,255,255,1.0)
#define ClearColor UIColorFromRGBA_D(0,0,0,0)
#define GoldenColor UIColorFromRGBA_D(198,157,64.1.0)
#define GoldenColorPressed  UIColorFromRGBA_D(198,157,64,0.5)

#define RedColor UIColorFromAlphaRGB_0x(0xD04B63,1)//红跌
#define GreenColor UIColorFromAlphaRGB_0x(0x01A86F,1)//绿涨

//字体
#define MainFontName @"PingFang-SC-Medium"
#define MainNumberFontName @"PingFang-SC-Medium"
#define YEAFONT(x) [UIFont fontWithName:MainFontName size:x]

#define IOS_VERSION      [[[UIDevice currentDevice] systemVersion] floatValue]

#define isIOS(version) ([[UIDevice currentDevice].systemVersion floatValue] >= version)

#define font(fontSize) [UIFont systemFontOfSize:fontSize]

#define fontBold(fontSize) [UIFont boldSystemFontOfSize:fontSize]


#define kScale(size)                                                ((kScreenWidth/375)*size)
#define zScale(size)                                                kScale(size)
#define kFontScale                                                  kScale(1)


//String
#define AssectString(param) [(param) isKindOfClass:[NSNumber class]] ? [((NSNumber *)param) stringValue] : ([(param) isKindOfClass:[NSString class]] ? ([[(param) lowercaseString] isEqualToString:@"null"] ? @"" : (param)): @"")
#define AssectNumber(param) !(param) || [(param) isEqualToString:@""]?@"0":(param)//String
#define AssectString(param) [(param) isKindOfClass:[NSNumber class]] ? [((NSNumber *)param) stringValue] : ([(param) isKindOfClass:[NSString class]] ? ([[(param) lowercaseString] isEqualToString:@"null"] ? @"" : (param)): @"")
#define AssectNumber(param) !(param) || [(param) isEqualToString:@""]?@"0":(param)

// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
                                \
                                [View.layer setCornerRadius:(Radius)];\
                                [View.layer setMasksToBounds:YES];\
                                [View.layer setBorderWidth:(Width)];\
                                [View.layer setBorderColor:[Color CGColor]]
// View 圆角
#define ViewRadius(View, Radius)\
                                \
                                [View.layer setCornerRadius:(Radius)];\
                                [View.layer setMasksToBounds:YES];\
                                [View.layer setShouldRasterize:YES];\
                                [View.layer setRasterizationScale:[UIScreen mainScreen].scale]
//打印信息
#ifdef DEBUG

#define ConsoleLog( s, ... ) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] )

#else
#define ConsoleLog( s, ... )
#endif

//弱引用
#ifndef weakObject
#if DEBUG
#if __has_feature(objc_arc)
#define weakObject(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object
#else
#define weakObject(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakObject(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakObject(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

//强引用
#ifndef strongObject
#if DEBUG
#if __has_feature(objc_arc)
#define strongObject(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongObject(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongObject(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongObject(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif

#endif /* Common_h */
